#!/bin/bash

# Kafka.cj 编译和测试脚本

echo "🚀 开始编译 Kafka.cj 库..."

# 检查 cjpm 是否可用
if ! command -v cjpm &> /dev/null; then
    echo "❌ 错误: cjpm 命令未找到，请确保已安装仓颉开发环境"
    exit 1
fi

# 编译库
echo "📦 编译库文件..."
if cjpm build; then
    echo "✅ 库编译成功"
else
    echo "❌ 库编译失败"
    exit 1
fi

# 编译示例程序
echo "🔨 编译示例程序..."

echo "  - 编译生产者示例..."
if cjpm build kafka.examples.producer; then
    echo "    ✅ 生产者示例编译成功"
else
    echo "    ❌ 生产者示例编译失败"
fi

echo "  - 编译消费者示例..."
if cjpm build kafka.examples.consumer; then
    echo "    ✅ 消费者示例编译成功"
else
    echo "    ❌ 消费者示例编译失败"
fi

echo "  - 编译客户端示例..."
if cjpm build kafka.examples.simple_client; then
    echo "    ✅ 客户端示例编译成功"
else
    echo "    ❌ 客户端示例编译失败"
fi

# 编译测试程序
echo "🧪 编译测试程序..."
if cjpm build kafka.tests.integration_test; then
    echo "    ✅ 集成测试编译成功"
else
    echo "    ❌ 集成测试编译失败"
fi

echo ""
echo "🎉 Kafka.cj 编译完成!"
echo ""
echo "📋 使用说明:"
echo "  运行生产者示例: cjpm run kafka.examples.producer"
echo "  运行消费者示例: cjpm run kafka.examples.consumer"  
echo "  运行客户端示例: cjpm run kafka.examples.simple_client"
echo "  运行集成测试:   cjpm run kafka.tests.integration_test"
echo ""
echo "⚠️  注意: 运行示例前请确保 Kafka 服务器运行在 localhost:9092"
echo ""
echo "📚 更多信息请查看 README.md 和 source/plan1.md"
